1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.Pattern;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.c.functions;
30 public  import glib.c.types;
31 private import linker.Loader;
32 
33 
34 /**
35  * A GPatternSpec struct is the 'compiled' form of a pattern. This
36  * structure is opaque and its fields cannot be accessed directly.
37  */
38 public class Pattern
39 {
40 	/** the main Gtk struct */
41 	protected GPatternSpec* gPatternSpec;
42 	protected bool ownedRef;
43 
44 	/** Get the main Gtk struct */
45 	public GPatternSpec* getPatternStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return gPatternSpec;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected void* getStruct()
54 	{
55 		return cast(void*)gPatternSpec;
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (GPatternSpec* gPatternSpec, bool ownedRef = false)
62 	{
63 		this.gPatternSpec = gPatternSpec;
64 		this.ownedRef = ownedRef;
65 	}
66 
67 	~this ()
68 	{
69 		if ( Linker.isLoaded(LIBRARY_GLIB[0]) && ownedRef )
70 			g_pattern_spec_free(gPatternSpec);
71 	}
72 
73 
74 	/**
75 	 * Compiles a pattern to a #GPatternSpec.
76 	 *
77 	 * Params:
78 	 *     pattern = a zero-terminated UTF-8 encoded string
79 	 *
80 	 * Returns: a newly-allocated #GPatternSpec
81 	 *
82 	 * Throws: ConstructionException GTK+ fails to create the object.
83 	 */
84 	public this(string pattern)
85 	{
86 		auto __p = g_pattern_spec_new(Str.toStringz(pattern));
87 
88 		if(__p is null)
89 		{
90 			throw new ConstructionException("null returned by new");
91 		}
92 
93 		this(cast(GPatternSpec*) __p);
94 	}
95 
96 	/**
97 	 * Copies @pspec in a new #GPatternSpec.
98 	 *
99 	 * Returns: a copy of @pspec.
100 	 *
101 	 * Since: 2.70
102 	 */
103 	public Pattern copy()
104 	{
105 		auto __p = g_pattern_spec_copy(gPatternSpec);
106 
107 		if(__p is null)
108 		{
109 			return null;
110 		}
111 
112 		return new Pattern(cast(GPatternSpec*) __p, true);
113 	}
114 
115 	/**
116 	 * Compares two compiled pattern specs and returns whether they will
117 	 * match the same set of strings.
118 	 *
119 	 * Params:
120 	 *     pspec2 = another #GPatternSpec
121 	 *
122 	 * Returns: Whether the compiled patterns are equal
123 	 */
124 	public bool equal(Pattern pspec2)
125 	{
126 		return g_pattern_spec_equal(gPatternSpec, (pspec2 is null) ? null : pspec2.getPatternStruct()) != 0;
127 	}
128 
129 	/**
130 	 * Frees the memory allocated for the #GPatternSpec.
131 	 */
132 	public void free()
133 	{
134 		g_pattern_spec_free(gPatternSpec);
135 		ownedRef = false;
136 	}
137 
138 	/**
139 	 * Matches a string against a compiled pattern. Passing the correct
140 	 * length of the string given is mandatory. The reversed string can be
141 	 * omitted by passing %NULL, this is more efficient if the reversed
142 	 * version of the string to be matched is not at hand, as
143 	 * g_pattern_match() will only construct it if the compiled pattern
144 	 * requires reverse matches.
145 	 *
146 	 * Note that, if the user code will (possibly) match a string against a
147 	 * multitude of patterns containing wildcards, chances are high that
148 	 * some patterns will require a reversed string. In this case, it's
149 	 * more efficient to provide the reversed string to avoid multiple
150 	 * constructions thereof in the various calls to g_pattern_match().
151 	 *
152 	 * Note also that the reverse of a UTF-8 encoded string can in general
153 	 * not be obtained by g_strreverse(). This works only if the string
154 	 * does not contain any multibyte characters. GLib offers the
155 	 * g_utf8_strreverse() function to reverse UTF-8 encoded strings.
156 	 *
157 	 * Params:
158 	 *     stringLength = the length of @string (in bytes, i.e. strlen(),
159 	 *         not g_utf8_strlen())
160 	 *     string_ = the UTF-8 encoded string to match
161 	 *     stringReversed = the reverse of @string or %NULL
162 	 *
163 	 * Returns: %TRUE if @string matches @pspec
164 	 *
165 	 * Since: 2.70
166 	 */
167 	public bool match(size_t stringLength, string string_, string stringReversed)
168 	{
169 		return g_pattern_spec_match(gPatternSpec, stringLength, Str.toStringz(string_), Str.toStringz(stringReversed)) != 0;
170 	}
171 
172 	/**
173 	 * Matches a string against a compiled pattern. If the string is to be
174 	 * matched against more than one pattern, consider using
175 	 * g_pattern_match() instead while supplying the reversed string.
176 	 *
177 	 * Params:
178 	 *     string_ = the UTF-8 encoded string to match
179 	 *
180 	 * Returns: %TRUE if @string matches @pspec
181 	 *
182 	 * Since: 2.70
183 	 */
184 	public bool matchString(string string_)
185 	{
186 		return g_pattern_spec_match_string(gPatternSpec, Str.toStringz(string_)) != 0;
187 	}
188 
189 	/**
190 	 * Matches a string against a compiled pattern. Passing the correct
191 	 * length of the string given is mandatory. The reversed string can be
192 	 * omitted by passing %NULL, this is more efficient if the reversed
193 	 * version of the string to be matched is not at hand, as
194 	 * g_pattern_match() will only construct it if the compiled pattern
195 	 * requires reverse matches.
196 	 *
197 	 * Note that, if the user code will (possibly) match a string against a
198 	 * multitude of patterns containing wildcards, chances are high that
199 	 * some patterns will require a reversed string. In this case, it's
200 	 * more efficient to provide the reversed string to avoid multiple
201 	 * constructions thereof in the various calls to g_pattern_match().
202 	 *
203 	 * Note also that the reverse of a UTF-8 encoded string can in general
204 	 * not be obtained by g_strreverse(). This works only if the string
205 	 * does not contain any multibyte characters. GLib offers the
206 	 * g_utf8_strreverse() function to reverse UTF-8 encoded strings.
207 	 *
208 	 * Deprecated: Use g_pattern_spec_match() instead
209 	 *
210 	 * Params:
211 	 *     pspec = a #GPatternSpec
212 	 *     stringLength = the length of @string (in bytes, i.e. strlen(),
213 	 *         not g_utf8_strlen())
214 	 *     string_ = the UTF-8 encoded string to match
215 	 *     stringReversed = the reverse of @string or %NULL
216 	 *
217 	 * Returns: %TRUE if @string matches @pspec
218 	 */
219 	public static bool patternMatch(Pattern pspec, uint stringLength, string string_, string stringReversed)
220 	{
221 		return g_pattern_match((pspec is null) ? null : pspec.getPatternStruct(), stringLength, Str.toStringz(string_), Str.toStringz(stringReversed)) != 0;
222 	}
223 
224 	/**
225 	 * Matches a string against a pattern given as a string. If this
226 	 * function is to be called in a loop, it's more efficient to compile
227 	 * the pattern once with g_pattern_spec_new() and call
228 	 * g_pattern_match_string() repeatedly.
229 	 *
230 	 * Params:
231 	 *     pattern = the UTF-8 encoded pattern
232 	 *     string_ = the UTF-8 encoded string to match
233 	 *
234 	 * Returns: %TRUE if @string matches @pspec
235 	 */
236 	public static bool patternMatchSimple(string pattern, string string_)
237 	{
238 		return g_pattern_match_simple(Str.toStringz(pattern), Str.toStringz(string_)) != 0;
239 	}
240 
241 	/**
242 	 * Matches a string against a compiled pattern. If the string is to be
243 	 * matched against more than one pattern, consider using
244 	 * g_pattern_match() instead while supplying the reversed string.
245 	 *
246 	 * Deprecated: Use g_pattern_spec_match_string() instead
247 	 *
248 	 * Params:
249 	 *     pspec = a #GPatternSpec
250 	 *     string_ = the UTF-8 encoded string to match
251 	 *
252 	 * Returns: %TRUE if @string matches @pspec
253 	 */
254 	public static bool patternMatchString(Pattern pspec, string string_)
255 	{
256 		return g_pattern_match_string((pspec is null) ? null : pspec.getPatternStruct(), Str.toStringz(string_)) != 0;
257 	}
258 }